package bookstore.servlet;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@Controller
@ResponseBody
@RequestMapping("/app/*")
public class SPARenderer {
    @GetMapping
    public void render(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println(this.getClass().getName());

        String index = request.getServletContext().getRealPath("/index.html");
        File html = new File(index);
        BufferedReader reader = new BufferedReader(new FileReader(html));
        PrintWriter out = response.getWriter();

        String tempString;
        while ((tempString = reader.readLine()) != null) {
            out.write(tempString);
        }
        reader.close();

        out.flush();
        out.close();
    }
}
